home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 February: Tool Chest / Dev.CD Feb 94.toast / Tool Chest / Development Platforms / MPW Related / Universal Interfaces / PPCCIncludes / fstream.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-13  |  2.6 KB  |  114 lines  |  [TEXT/MPS ]

  1. /***********************************************************
  2.           FSTREAM.H
  3. *********************************************************/
  4.  
  5.  
  6. #ifndef FSTREAMH
  7. #define FSTREAMH
  8.  
  9. #ifndef IOSTREAMH
  10. #include <iostream.h>
  11. #endif
  12.  
  13. class  filebuf : public streambuf {    /* a stream buffer for files */
  14. public:
  15.     static const int openprot ; /* default protection for open */
  16. public:
  17.             filebuf() ;
  18.             filebuf(int fd);
  19.             filebuf(int fd, char*  p, int l) ;
  20.  
  21.     int        is_open() { return opened ; }
  22.     int        fd() { return xfd ; }
  23.     filebuf*    open(const char *name, int om, int prot=openprot);
  24.     filebuf*    attach(int fd) ;
  25.     filebuf*     close() ;
  26.             ~filebuf() ;
  27. public: /* virtuals */
  28.     virtual int    overflow(int=EOF);
  29.     virtual int    underflow();
  30.     virtual int    sync() ;
  31.     virtual streampos
  32.             seekoff(streamoff,ios::seek_dir,int) ;
  33.     virtual streambuf*
  34.             setbuf(char*  p, int len) ;
  35.     virtual int    xsputn(const char*  s,int n);
  36. protected:
  37.     int        xfd;    
  38.     int        mode ;
  39.     char        opened;
  40.     streampos    last_seek ;
  41.     char*         in_start;
  42.     int        last_op();
  43.     char        lahead[2] ;
  44. };
  45.  
  46. class fstreambase : virtual public ios { 
  47. public:
  48.             fstreambase() ;
  49.     
  50.             fstreambase(const char* name, 
  51.                     int mode,
  52.                     int prot=filebuf::openprot) ;
  53.             fstreambase(int fd) ;
  54.             fstreambase(int fd, char*  p, int l) ;
  55.             ~fstreambase() ;
  56.     void        open(const char* name, int mode, 
  57.                     int prot=filebuf::openprot) ;
  58.     void        attach(int fd);
  59.     void        close() ;
  60.     void        setbuf(char*  p, int l) ;
  61.     filebuf*    rdbuf() { return &buf ; }
  62. private:
  63.     filebuf        buf ;
  64. protected:
  65.     void        verify(int) ;
  66. } ;
  67.  
  68. class ifstream : public fstreambase, public istream {
  69. public:
  70.             ifstream() ;
  71.             ifstream(const char* name, 
  72.                     int mode=ios::in,
  73.                     int prot=filebuf::openprot) ;
  74.             ifstream(int fd) ;
  75.             ifstream(int fd, char*  p, int l) ;
  76.             ~ifstream() ;
  77.  
  78.     filebuf*    rdbuf() { return fstreambase::rdbuf(); }
  79.     void        open(const char* name, int mode=ios::in, 
  80.                     int prot=filebuf::openprot) ;
  81. } ;
  82.  
  83. class ofstream : public fstreambase, public ostream {
  84. public:
  85.             ofstream() ;
  86.             ofstream(const char* name, 
  87.                     int mode=ios::out,
  88.                     int prot=filebuf::openprot) ;
  89.             ofstream(int fd) ;
  90.             ofstream(int fd, char*  p, int l) ;
  91.             ~ofstream() ;
  92.  
  93.     filebuf*    rdbuf() { return fstreambase::rdbuf(); }
  94.     void        open(const char* name, int mode=ios::out, 
  95.                     int prot=filebuf::openprot) ;
  96. } ;
  97.  
  98. class fstream : public fstreambase, public iostream {
  99. public:
  100.             fstream() ;
  101.     
  102.             fstream(const char* name, 
  103.                     int mode,
  104.                     int prot=filebuf::openprot) ;
  105.             fstream(int fd) ;
  106.             fstream(int fd, char*  p, int l) ;
  107.             ~fstream() ;
  108.     filebuf*    rdbuf() { return fstreambase::rdbuf(); }
  109.     void        open(const char* name, int mode, 
  110.                 int prot=filebuf::openprot) ;
  111. } ;
  112.  
  113. #endif
  114.